package GroupName.Project_1;

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public abstract class LongTimeButtonActionListener implements ActionListener{
	
	public void actionPerformed(ActionEvent e) {
		if(init()==false){ return ;}					//初始化失败，直接放弃后续操作。
		new Thread(new TaskRun()).start();				//执行长耗时任务。
	}
	
	abstract public void task();
	abstract public void finish();
	abstract public boolean init();
	
	private class TaskRun implements Runnable{
		public void run() {
			task();
			EventQueue.invokeLater(new Runnable(){
				public void run() {
					finish();
				}
			});
		}
	}
}
